package com.css.apps.base.common.provider;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.css.apps.base.post.model.SPost;

import com.css.db.query.QueryCache;

public class PostQueryProvider {

	public static SPost getPost(String postId) {
		return QueryCache.get(SPost.class, postId);
	}

	@SuppressWarnings("unchecked")
	public static Map<String, List<SPost>> getPosts() {
		Map<String, List<SPost>> result = new HashMap<String, List<SPost>>();
		List<Object[]> list = new QueryCache("select b.orgId,a.uuid from SPost a , SOrgPost b where a.uuid=b.postId ")
				.list();
		if (list != null && list.size() > 0) {
			for (Object[] os : list) {
				List<SPost> posts = result.get(os[0]);
				if (posts == null) {
					posts = new ArrayList<SPost>();
				}
				posts.add(QueryCache.get(SPost.class, (String) os[1]));
				result.put((String) os[0], posts);
			}
		}
		return result;
	}
	
}
